<!DOCTYPE html>
<html lang="zc-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        //让用户输入五个有效年龄（0-100之间），**放入数组中**
        let arr = []
        for (let i = 0; i < 5; i++) {
            for (; ;) {
                let age = +prompt(`请输入第${i + 1}有效年龄`)
                if (age >= 0 && age <= 100) {
                    arr.push(age)
                    break
                }else {
                    
                }
            }

        }

        document.write(arr);
        //打印成年年龄
        for (let i = 0; i < arr.length; i++) {
            if (arr[i] >= 18) {
                console.log(`数组中成年年龄是${arr[i]}`);
            }
        }
        //打印所有人总年龄
        let sum = 0
        for (let i = 0; i < arr.length; i++) {
            sum += arr[i]
        }
        console.log(`所有人年龄总和是${sum}`);
        //打印所有人的平均年龄
        let sum2 = 0
        for (let i = 0; i < arr.length; i++) {
            sum2 += arr[i]
        }
        console.log(`所有人平均年龄是${sum2 / arr.length}`);
        //打印出最大年龄和最小年龄
        let max = arr[0]
        let min = arr[0]
        for (let i = 0; i < arr.length; i++) {
            if (max < arr[i]) {
                max = arr[i]
            }
            if (min > arr[i]) {
                min = arr[i]
            }
        }
        console.log(`最大年龄是${max}`);
        console.log(`最小年龄是${min}`);
    </script>
</body>

</html>